import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        String s = "aaaaaa";
        s.toCharArray()
        StringBuilder ans = new StringBuilder();
        System.out.println(s.lastIndexOf("a"));
        System.out.println(Integer.parseInt("099"));
    }
}
class Solution {
    public int monotoneIncreasingDigits(int n) {
        String s = String.valueOf(n);
        int flag = s.length();
        char[] ch = s.toCharArray();
        for(int i=ch.length-1; i>0; i--){
            if(ch[i]<ch[i-1]){
                ch[i-1]--;
                flag = i;
            }
        }
        for(int i=flag; i<ch.length; i++){
            ch[i] = '9';
        }
        return Integer.parseInt(new String(ch));
    }
}
class Solution {
    //0-无覆盖 1-有监控 2-有覆盖
    int ans = 0;
    private int dfs(TreeNode root){
        if(root == null) return 2;
        int left = dfs(root.left);
        int right = dfs(root.right);
        //左右都覆盖，父节点为无覆盖，让父父节点为监控
        if(left == 2 && right == 2) return 0;
        //左右至少有一个无覆盖，父节点为监控
        if(left == 0 || right == 0){
            ans++;
            return 1;
        }
        //左右至少有一个有监控，父节点为覆盖
        if(left == 1 || right == 1) return 2;
        return -1;//不会运行到这里
    }
    public int minCameraCover(TreeNode root) {
        ans = 0;
        if(dfs(root) == 0){//根节点无覆盖
            ans++;
        }
        return ans;
    }
}
